import { getAllCity } from '@/services/auth';

const model = {
  namespace: 'allcity',
  state: {
    cityList: []
  },
  effects: {
    *getCityByPage({ payload }, { call, put, select }) {
      const { cityList } = yield select(_ => _.allcity);
      if (cityList.length) {
        console.log(cityList)
        return cityList;
      } else {
        const { code, message, data } = yield call(getAllCity, payload);
        if (code === '000000') {
          yield put({
            type: 'putList',
            payload: data
          });
          return data;
        }
      }
    },
  },
  reducers: {
    putList(state, action) {
      const { payload } = action;
      return { ...state, cityList: payload };
    },
  },
};
export default model;
